home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / prolog_2.zip / UTILITY.ZIP / DIAL411.PRO < prev   
Text File  |  1986-07-20  |  3KB  |  103 lines

  1. /* This program modified by Bob Morein 3/1/86. */
  2.  
  3.  
  4. mem(X, [X|_] ).
  5. mem(X,[_|Y] ) :- mem(X, Y).
  6.  
  7. anymem(X,Y) :- mem(X,Y),!.
  8.  
  9. ppt( [H|T], I ) :- !, J is I+3, ppt(H, J), ppxt(T, J), nl.
  10. ppt( X, I ) :- tab(I), print(X), nl.
  11.  
  12. ppxt( [], _ ).
  13. ppxt( [H|T], I ) :- ppt(H, I), ppxt(T, I).
  14.  
  15. affirm(Choice) :-
  16.     print(Choice),
  17.     print(' (y/n) ?>>'),
  18.     get0(C),
  19.     mem(C,"yY").
  20.  
  21. /* ------------   core of dial_411 program -------------*/
  22. query(Last,First,Address) :-
  23.     nl,nl,
  24.     print('Enter query data with entry format:'),nl,
  25.     print('Last Name    >>'),
  26.     ratom(Last),
  27.     print('First Name   >>'),
  28.     ratom(First),
  29.     print('# or Address >>'),
  30.     ratom(Address).
  31.  
  32. search(Ll,Ff,Aa) :-
  33.     print('\nseeking... '),
  34.     data( H ),
  35.     [L,F,A] = H, 
  36.     ( Ll = [] ; anymem(Ll,L) ),
  37.     ( Ff = [] ; anymem(Ff,F) ),
  38.     ( Aa = [] ; anymem(Aa,A) ),
  39.     nl, ppt(H,0),
  40.     affirm('\nStop searching this query'), !.
  41. search(L,Ff,Aa) :-
  42.     print('\nThis search over, no (more) matches on the query.').
  43.  
  44. direct :-
  45.      repeat,
  46.      query(A,B,C),
  47.      search(A,B,C), fails,
  48.      affirm('\nQuit directory').
  49.  
  50. /* lead-off predicate */
  51. dial_411 :-
  52.      directory_message,
  53.      affirm('\n\nContinue with directory, and initiate a query/search '),
  54.      direct,
  55.      print('\nQuitted directory.'),
  56.      !,fails.
  57. dial_411 :- print('\nQuitted directory.'),!,fails.
  58. /* ----------------------- end core -------------------------------*/
  59.  
  60. /* ----------------- start directory_message ------------------------------ */
  61. directory_message :-
  62.  
  63. print('\nThe program "directory" gets you directory information by household.'),
  64. print('\nThe data of each household are in 3 categories :'),
  65. print('\n   1)last names,         e.g.  Blacquier' ),
  66. print('\n   2)first names,              Fred     '),
  67. print('\n   3)phone # & address lines   Carlisle  OR  01741 .'),
  68. nl,
  69. print('\nTo query directory, enter ONE datum for EACH category.'),
  70. print('\nDirectory then seeks a match with these data, e.g. with: '),
  71. print('\n     last name>><Return>   (wildcard datum) '),
  72. print('\n    first name>><Return>   (wildcard datum) '),
  73. print('\n   # & address>> \'Carlisle\'.     <Return>  .'),
  74. nl,
  75. print('\nEntry spellings & Caps must match in the database EXACTLY, or they fails.'),
  76. print('\nWILDCARD datums always succeed (being anonymous variables).'),
  77. print('\nA wildcard entry is a carriage return.'),
  78. print('\nClose your entries and replies with a <Return> .'),
  79. nl,
  80. print('\nSome queries (esp. wildcards) can generate multiple matches.  The '),
  81. print('\ninterpreter will ask if you seek more matchups to a query, or not.'),
  82. print('\n    to  STOP  this program  use:   <Esc>    OR    <Ctrl-C>'),
  83. print('\n    to  QUIT  Pdprolog use:   ?-exitsys.').
  84. /* --------------------- end message ----------------------------------- */
  85.  
  86. /* --------------- start, directory household data --------------------- */
  87.  
  88. data([ 
  89.      ['ADA'],
  90.      ['Robert Morein'],
  91.      ['215/646-4894','1570 Arran Way','Dresher','PA','19025'] 
  92.      ]).
  93. data([ 
  94.      ['Brown'],
  95.      ['Amy'],
  96.      ['953-8626', '61 College Ave', 'Medford', '02138'] 
  97.      ]).
  98.  
  99. /* ---------------- end, directory household data --------------------- */
  100.  
  101. ?-directory_message, direct.
  102.  
  103.